﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKSparseDistance.Properties;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseDistance.ModelLayer
{
	internal class BoundaryCurveBean : BaseCurveBean
	{
		public Curve ThisBaseCurve
		{
			get
			{
				return this.m_thisBaseCurve;
			}
		}

		public BaseBoundarySegmentPacker ThisPacker
		{
			get
			{
				return this.m_thisPacker;
			}
		}

		public Curve ThisBaseOffestCurve
		{
			get
			{
				return this.m_thisBaseOffestCurve;
			}
		}

		public Curve RealOffestCurve
		{
			get
			{
				return this.m_RealOffestCurve;
			}
		}

		public List<Curve> LstAppendOffestCurve
		{
			get
			{
				return this.m_lstAppendOffestCurve;
			}
		}

		public List<Curve> LstOffestLinkCurve
		{
			get
			{
				return this.m_lstOffestLinkCurve;
			}
		}

		public bool IfFreeEndBoundary
		{
			get
			{
				return this.m_bIfFreeEndBoundary;
			}
			private set
			{
				this.m_bIfFreeEndBoundary = value;
			}
		}

		public void SetCutedCurves(object inputValue)
		{
			if (inputValue is Curve && null != inputValue as Curve)
			{
				this.m_RealOffestCurve = (inputValue as Curve);
				return;
			}
			if (inputValue is List<Curve> && inputValue is List<Curve>)
			{
				this.m_RealOffestCurve = null;
				this.m_lstAppendOffestCurve = (inputValue as List<Curve>);
			}
		}

		private void SetEndLink()
		{
			this.m_lstOffestLinkCurve = new List<Curve>();
			if (null != this.m_RealOffestCurve)
			{
				this.m_lstOffestLinkCurve = Utility.MakeEndCurves(this.m_thisBaseCurve, this.m_RealOffestCurve);
				return;
			}
			if (null != this.m_thisBaseOffestCurve)
			{
				this.m_lstOffestLinkCurve = Utility.MakeEndCurves(this.m_thisBaseCurve, this.m_thisBaseOffestCurve);
			}
		}

		public override List<BulidingCurvePakcer> LstCurvePacker
		{
			get
			{
				List<BulidingCurvePakcer> list = new List<BulidingCurvePakcer>();
				if (!this.IfFreeEndBoundary && !this.m_bIfFreeEndBoundary)
				{
					list.AddRange(this.m_lstCurvePacker);
				}
				if (this.m_lstAppendOffestCurve != null && this.m_lstAppendOffestCurve.Count != 0)
				{
					using (List<Curve>.Enumerator enumerator = this.m_lstAppendOffestCurve.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							Curve inputCurve = enumerator.Current;
							if (this.m_bIfIsWallBoundary)
							{
								list.Add(new BulidingCurvePakcer(inputCurve, this.m_thisPacker, true, false, this.IfFreeEndBoundary, false));
							}
							else
							{
								list.Add(new BulidingCurvePakcer(inputCurve, this.m_thisPacker, true, false, this.IfFreeEndBoundary, false));
							}
						}
						goto IL_108;
					}
				}
				if (null != this.NowCanUseCurve())
				{
					if (this.m_bIfIsWallBoundary)
					{
						list.Add(new BulidingCurvePakcer(this.NowCanUseCurve(), this.m_thisPacker, true, this.IfFreeEndBoundary, this.IfFreeEndBoundary, false));
					}
					else
					{
						list.Add(new BulidingCurvePakcer(this.NowCanUseCurve(), this.m_thisPacker, true, this.IfFreeEndBoundary, this.IfFreeEndBoundary, false));
					}
				}
				IL_108:
				if (!this.IfFreeEndBoundary)
				{
					this.SetEndLink();
					foreach (Curve inputCurve2 in this.m_lstOffestLinkCurve)
					{
						list.Add(new BulidingCurvePakcer(inputCurve2, this.m_thisPacker, true, false, false, false));
					}
				}
				return list;
			}
		}

		public BoundaryCurveBean(Curve inputCurve, BaseBoundarySegmentPacker usePacker, bool ifFreeEnd = false)
		{
			this.m_thisBaseCurve = inputCurve;
			this.IfFreeEndBoundary = ifFreeEnd;
			this.m_lstCurvePacker.Add(new BulidingCurvePakcer(this.m_thisBaseCurve, this.m_thisPacker, false, false, false, false));
			this.m_thisPacker = usePacker;
			if (usePacker.ThisElement != null && usePacker.ThisElement is Wall)
			{
				this.m_bIfIsWallBoundary = true;
			}
			this.m_thisBaseOffestCurve = Utility.GetAOffestCurveInRoom(this.m_thisBaseCurve, usePacker.ThisRoomPacker.ThisRoom, double.Parse(Resources.Str_OffestValue));
		}

		public Curve NowCanUseCurve()
		{
			if (null == this.RealOffestCurve)
			{
				return this.m_thisBaseOffestCurve;
			}
			return this.m_RealOffestCurve;
		}

		public List<Curve> NowOffestCurve()
		{
			if (this.m_lstAppendOffestCurve != null && this.m_lstAppendOffestCurve.Count != 0)
			{
				return this.m_lstAppendOffestCurve;
			}
			List<Curve> list = new List<Curve>();
			if (null != this.NowCanUseCurve())
			{
				list.Add(this.NowCanUseCurve());
			}
			return list;
		}

		private Curve m_thisBaseCurve;

		private BaseBoundarySegmentPacker m_thisPacker;

		private Curve m_thisBaseOffestCurve;

		private Curve m_RealOffestCurve;

		private bool m_bIfFreeEndBoundary;

		private List<Curve> m_lstAppendOffestCurve;

		private List<Curve> m_lstOffestLinkCurve;

		private bool m_bIfIsWallBoundary;
	}
}
